<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/vue2.6.12.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
	</head>
	<body>
		<div id="app">
			<button type="button" @click="getData">点击加载数据</button>
			<child1 v-for="item in lst"  :lst="item"></child1>
			<child2></child2>
		</div>
	</body>
	<script type="text/javascript">
		var bus=new Vue();
		
		Vue.component('child1',{
			props:['lst'],
			template:`
				<div>
					{{lst.name}} <button @click="btnc1">链接</button>
				</div>
			`,
			methods:{
				btnc1(){
					//传递数据，指定名称为 trl
					bus.$emit('trl',this.lst.postUrlForShare);
				}
			},
			
		});
		
		Vue.component('child2',{
			data(){
				return {
					url:'',
				}
			},
			template:`
				<div>
					<p> {{url}} </p>
				</div>
			`,
			mounted(){
				//是一个函数, 监控 trl
				bus.$on('trl',(data)=>{
					this.url=data
				})
			}
		});
		
		
		var vm = new Vue({
			el:'#app',
			data:{
				lst:''
			},
			methods:{
				getData(){
					axios.get("../json/info.json").then((data)=>{
						this.lst=data.data.data;
					})
				}
			}
		})
	</script>
</html>
